import { message } from "antd"

export function formatTime(time: string, type: "FULL_TIME" | "ONLY_DAY") {
  const date = new Date(Number(time))
  const year = date.getFullYear()
  const month = ((date.getMonth() + 1).toString()).padStart(2, "0")
  const day = (date.getDate().toString()).padStart(2, "0")
  const hour = (date.getHours().toString()).padStart(2, "0")
  const minute = (date.getMinutes().toString()).padStart(2, "0")
  const second = (date.getSeconds().toString()).padStart(2, "0")
  const onlyDay = `${year}-${month}-${day}`
  const fullTime = `${onlyDay} ${hour}:${minute}:${second}`
  if (type === "FULL_TIME") {
    return fullTime
  } else {
    return onlyDay
  }
}

export function myTip(info: string, type?: "success" | "fail" | "loading" | "normal" | "warning") {
  message.destroy("mes")
  switch (type) {
    case "success":
      message.success({ content: info, key: "mes", duration: 1.5 })
      return
    case "fail":
      message.error({ content: info, key: "mes", duration: 1.5 })
      return
    case "loading":
      message.loading({ content: info, key: "mes", duration: 1.5 })
      return
    case "normal":
      message.info({ content: info, key: "mes", duration: 1.5 })
      return
    case "warning":
      message.warning({ content: info, key: "mes", duration: 1.5 })
      return
    default:
      message.info({ content: info, key: "mes", duration: 1.5 })
      return
  }
}